$(function () {
    // 初始化内容
    var basePath=getContextPath();
    $("#settingMenu").attr("class","active");
    $("#breadcrumb").html("系统设置");
    $("#myAlert").css('display', 'none');
    init(basePath);
    $("#btnSubmit").click(function () {
        var password = $("#password").val();
        var apiHisUrl = $("#apiHisUrl").val();
        var apiNowUrl = $("#apiNowUrl").val();
        var apiUser = $("#apiUser").val();
        var apiPass = $("#apiPass").val();
        var intervalTime = $("#intervalTime").val();
        var id = $("#id").val();
        $("#btnSubmit").text("数据请求中...");
        $("#btnSubmit").attr("disabled","true");
        $.post(basePath+"/back/setting/edit",
            {
                "password": password,
                "apiHisUrl": apiHisUrl,
                "apiNowUrl": apiNowUrl,
                "apiUser": apiUser,
                "apiPass": apiPass,
                "intervalTime": intervalTime,
                "id": id
            },
            function (data) {
                $("#myAlert").css('display', 'block');
                $("#alertMsg").html(data.message);
                $("#btnSubmit").text("提交");
                $("#btnSubmit").removeAttr("disabled");
                setTimeout(function(){$("#myAlert").hide()}, 2000);
            }
        );
    });
});

function init(basePath) {
    $.ajax({
        url: basePath+"/back/setting/info",
        type: "get",
        dataType: "json",
        success: function (data) {
            if (data != null) {
                $("#username").val(data.username);
                $("#password").val(data.password);
                $("#apiHisUrl").val(data.apiHisUrl);
                $("#apiNowUrl").val(data.apiNowUrl);
                $("#id").val(data.id);
                $("#apiUser").val(data.apiUser);
                $("#apiPass").val(data.apiPass);
                $("#intervalTime").val(data.intervalTime);
            }
        }
    });
}
